<template>
	<view style="background-color: #fff;">
		<view class="invite_adv">
			<image :src="$util.img('/upload/uniapp/member/invite/top_bg.png')" mode="widthFix"></image>

			<view class="desc" @click="openRulePopup">
				<i class="iconfont iconbangzhu"></i>
				活动说明
			</view>
			<image class="font" :src="$util.img('/upload/uniapp/member/invite/top_font.png')" mode="widthFix"></image>
			<view class="time">活动时间：{{ $util.timeStampTurnTime(info.start_time, 1) }}至{{ $util.timeStampTurnTime(info.end_time, 1) }}</view>
			、
			<!-- #ifdef H5 -->
			<view class="btn" :style="{ 'background-image': 'url(' + $util.img('/upload/uniapp/member/invite/top_btn.png') + ')' }" @click="openSharePopup">立即邀请</view>
			<!-- #endif -->
			<!-- #ifdef MP -->
			<button class="btn" open-type="share" :style="{ 'background-image': 'url(' + $util.img('/upload/uniapp/member/invite/top_btn.png') + ')' }">喊好友来砍一刀</button>
			<!-- #endif -->
		</view>
		<view class="content">
			<view class="title">我的好友</view>
			<block v-if="inviteList.length > 0">
				<view class="invitelist_block">
					<view class="invitelist">
						<view class="list-item" v-for="(item, index) in inviteList">
							<view class="list-left">
								<view class="img color-base-border"><image mode="aspectFit" :src="$util.img(item.headimg)"></image></view>
								<view class="info">
									<view class="name font-size-tag">{{ item.source_member_nickname }}</view>
									<view class="time font-size-activity-tag color-tip">{{ $util.timeStampTurnTime(item.create_time) }}</view>
								</view>
							</view>
							<view class="prize color-base-text font-size-activity-tag">
								<block v-if="item.balance > 0">{{ item.balance }}元现金红包</block>
								<block v-if="(item.point > 0 || item.coupon_num) && item.balance > 0">+</block>
								<block v-if="item.point > 0">{{ parseInt(item.point) }}积分</block>
								<block v-if="item.point > 0 && item.balance > 0 && item.coupon_num > 0">+</block>
								<block v-if="item.coupon_num > 0">{{ item.coupon_num }}张优惠券</block>
							</view>
						</view>
					</view>
					<view class="more_invite color-tip font-size-tag " @click="moreList" v-if="isClick && total_num > page">
						查看更多
						<text class="iconfont iconiconangledown"></text>
					</view>
					<view class="more_invite color-tip font-size-tag " @click="moreList" v-if="!isClick && inviteList.length > 5 && total_num <= page">没有更多数据了</view>
				</view>
			</block>
			<block v-else>
				<view class="empty">
					<view class="tip">您还没有好友哦</view>
					<view class="tip">邀请好友，赚取好礼。赶紧去试试吧~</view>
				</view>
			</block>
		</view>
		<view class="content">
			<view class="title">邀请好友奖励</view>
			<view class="invite_active">
				<view class="list">
					<view class="item" v-if="info.balance > 0">
						<image :src="$util.img('/upload/uniapp/member/invite/coupon_bg.png')" mode="aspectFill"></image>
						<view class="desc">
							<view class="price">
								￥
								<text>{{ info.balance }}</text>
							</view>
							<view class="type">现金红包</view>
						</view>
					</view>

					<view class="item" v-if="info.point">
						<image :src="$util.img('/upload/uniapp/member/invite/coupon_bg.png')" mode="aspectFill"></image>
						<view class="desc">
							<view class="price">
								<text>{{ parseInt(info.point) }}</text>
							</view>
							<view class="type">积分</view>
						</view>
					</view>

					<view class="item margin_right_none" v-if="info.coupon">
						<image :src="$util.img('/upload/uniapp/member/invite/coupon_bg.png')" mode="aspectFill"></image>
						<view class="desc">
							<view class="price">
								<text>{{ info.coupon }}</text>
								张
							</view>
							<view class="type">优惠券</view>
						</view>
					</view>
				</view>
				<view class="desc">
					<view class="title_desc color-tip">分享给好友，让好友通过你的分享链接进入并注册登录，可随机获得以下奖励：</view>
					<view class="desc_list">
						<view class="" v-if="info.balance">
							<text>●</text>
							可得{{ info.balance }}元红包奖励，每月最多可得{{ info.max_balance }}元红包
						</view>
						<view class="" v-if="info.point">
							<text>●</text>
							可得{{ info.point }}积分，每月最多可得{{ info.max_point }}积分
						</view>
						<view class="" v-if="info.coupon">
							<text>●</text>
							可得{{ info.coupon }}张优惠券，每月最多可得{{ info.max_coupon }}张优惠券
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content">
			<view class="title">如何邀请好友</view>
			<view class="invite_active">
				<view class="step">
					<view>
						<view class="img"><image :src="$util.img('/upload/uniapp/member/invite/fenxiang.png')" mode="aspectFit"></image></view>
						<view class="text">分享链接给好友</view>
					</view>
					<view><image :src="$util.img('/upload/uniapp/member/invite/jiantou.png')" class="jiantou"></image></view>
					<view>
						<view class="img"><image :src="$util.img('/upload/uniapp/member/invite/shouji.png')" mode="aspectFit"></image></view>
						<view class="text">好友进入并注册登录</view>
					</view>
					<view><image :src="$util.img('/upload/uniapp/member/invite/jiantou.png')" class="jiantou"></image></view>
					<view>
						<view class="img"><image :src="$util.img('/upload/uniapp/member/invite/hongbao.png')" mode="aspectFit"></image></view>
						<view class="text">好友绑定成功获得奖励</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 分享弹窗 -->
		<view @touchmove.prevent.stop>
			<uni-popup ref="sharePopup" type="bottom" class="share-popup">
				<view>
					<view class="share-title">分享</view>
					<view class="share-content">
						<!-- #ifdef H5 -->
						<view class="share-box" @click="copyUrl">
							<button class="share-btn" :plain="true">
								<view class="iconfont iconfuzhilianjie"></view>
								<text>复制链接</text>
							</button>
						</view>
						<!-- #endif -->
					</view>
					<view class="share-footer" @click="closeSharePopup"><text>取消分享</text></view>
				</view>
			</uni-popup>
		</view>

		<!-- 弹出规则 -->
		<view @touchmove.prevent.stop>
			<uni-popup ref="rulePopup" type="bottom">
				<view class="tips-layer">
					<view class="head" @click="closeRulePopup()">
						<view class="title">规则说明</view>
						<text class="iconfont iconclose"></text>
					</view>
					<view class="body">
						<view class="detail margin-bottom">{{ info.remark }}</view>
					</view>
				</view>
			</uni-popup>
		</view>
		<ns-login ref="login"></ns-login>
	</view>
</template>

<script>
export default {
	data() {
		return {
			token: '',
			inviteList: [],
			memberId: 0,
			info: {},
			page: 1,
			page_size: 5,
			total_num: 0,
			isClick: true
		};
	},
	onLoad(option) {
		this.token = uni.getStorageSync('token');
		if (option.source_member) {
			this.memberId = option.source_member;
			uni.setStorageSync('source_member', option.source_member);
		}
		this.getBaseInfo();
		if (uni.getStorageSync('token')) {
			this.getMemberId();
			this.getList();
		}
	},
	methods: {
		//获取邀请列表
		getList() {
			this.$api.sendRequest({
				url: '/memberrecommend/api/memberrecommend/lists',
				data: {
					page: this.page,
					page_size: this.page_size
				},
				success: res => {
					this.inviteList = this.inviteList.concat(res.data.list);
					this.total_num = res.data.page_count;
				}
			});
		},
		moreList() {
			this.page++;
			this.isClick = false;
			if (this.page < this.total_num) {
				this.getList();
				this.isClick = true;
			} else if (this.page == this.total_num) {
				this.getList();
			}
		},
		getBaseInfo() {
			this.$api.sendRequest({
				url: '/memberrecommend/api/memberrecommend/info',
				success: res => {
					this.info = res.data;
				}
			});
		},
		getMemberId() {
			this.$api.sendRequest({
				url: '/api/member/id',
				success: res => {
					if (res.code >= 0) {
						this.memberId = res.data;
						this.token = uni.getStorageSync('token');
					}
				}
			});
		},
		openSharePopup() {
			uni.setStorageSync('source_member', this.memberId);
			if (!this.token) {
				this.$refs.login.open('/otherpages/member/invite_friends/invite_friends?source_member=' + this.memberId);
			} else {
				this.$refs.sharePopup.open();
			}
		},
		// 关闭分享弹出层
		closeSharePopup() {
			this.$refs.sharePopup.close();
		},
		// 打开规则说明弹出层
		openRulePopup() {
			this.$refs.rulePopup.open();
		},
		// 打开规则说明弹出层
		closeRulePopup() {
			this.$refs.rulePopup.close();
		},
		copyUrl() {
			let text = this.$config.h5Domain + '/otherpages/member/invite_friends/invite_friends?';
			if (this.memberId) text += 'source_member=' + this.memberId;
			this.$util.copy(text, () => {
				this.closeSharePopup();
			});
		}
	}
};
</script>

<style lang="scss">
.invite_adv {
	position: relative;
	image {
		height: 100%;
		width: 100%;
	}
	.desc {
		position: absolute;
		top: 0;
		right: 10rpx;
		text-align: right;
		color: #fff;
		padding: 20rpx;
		font-size: $font-size-tag;
		.title_desc {
			font-size: $font-size-tag;
		}
		.iconfont {
			font-size: $font-size-tag;
			margin-right: 10rpx;
		}
	}
	.time {
		position: absolute;
		bottom: 120rpx;
		text-align: center;
		width: 100%;
		color: #fff;
	}
	.font {
		position: absolute;
		bottom: 220rpx;
		text-align: center;
		width: 333rpx;
		height: 186rpx;
		z-index: 5;
		left: calc((100% - 333rpx) / 2);
	}
	.btn {
		position: absolute;
		background-size: cover;
		background-repeat: no-repeat;
		text-align: center;
		width: 610rpx;
		line-height: 112rpx;
		height: 126rpx;
		left: calc((100% - 610rpx) / 2);
		color: #ff0029;
		bottom: -24rpx;
		font-size: 36rpx;
		font-weight: bold;
	}
}
.more_invite {
	text-align: center;
	padding: 30rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}
.content {
	padding: 30rpx;
	margin-top: 50rpx;
	.title {
		font-size: $font-size-toolbar;
		color: #000;
		font-weight: 500;
	}
	.empty {
		padding: 50rpx;
		.tip {
			font-size: $font-size-base;
			color: #999999;
			text-align: center;
		}
	}
	.invitelist_block {
		border: 1px solid $color-line;
		border-radius: $border-radius;
		margin-top: $margin-both;
		background-color: #fff;
	}
	.invitelist {
		.list-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx 24rpx;
			.list-left {
				display: flex;
				.img {
					width: 70rpx;
					height: 70rpx;
					border-radius: 70rpx;
					border: 1px solid;
					margin-right: $margin-updown;
					overflow: hidden;
					image {
						width: 100%;
						height: 70rpx;
						overflow: hidden;
					}
				}
				.info {
				}
			}
			.prize {
				max-width: 50%;
				margin-left: 20rpx;
			}
		}
	}
	.invite_active {
		.list {
			display: flex;
			margin-top: 37rpx;
			.item {
				position: relative;
				width: 232rpx;
				height: 214rpx;
				&.margin_right_none {
					margin: 0;
				}
				image {
					width: 100%;
					height: 100%;
				}
				.desc {
					position: absolute;
					top: 0;
					text-align: center;
					width: 100%;
					.price {
						text-align: center;
						background-image: -webkit-linear-gradient(bottom, #ff2440, #ff7b7b);
						-webkit-background-clip: text;
						-webkit-text-fill-color: transparent;
						font-size: 30rpx;
						font-weight: 500;
						line-height: 1;
						text {
							font-size: 50rpx;
						}
					}
					.type {
						font-size: $font-size-tag;
						color: #666666;
					}
				}
			}
			.item:last-child {
				margin-right: 0rpx !important;
			}
		}
		.desc {
			color: #999999;
			padding: 30rpx 0;

			.title {
				color: #999999;
				font-weight: 400;
			}
			.desc_list {
				view {
					color: #999999;
					display: flex;
					text {
						font-size: $font-size-activity-tag;
						margin-right: 10rpx;
						align-self: center;
					}
				}
			}
		}
	}
	.step {
		display: flex;
		align-items: center;
		margin-top: 80rpx;
		padding-bottom: 80rpx;
		> view {
			text-align: center;
			width: 20%;
			display: flex;
			flex-direction: column;

			.img {
				width: 56rpx;
				height: 56rpx;
				margin: auto;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.text {
				margin-top: 20rpx;
				font-size: $font-size-tag;
				color: $color-tip;
			}
			.jiantou {
				width: 40rpx;
				height: 24rpx;
				margin: auto;
			}
		}
	}
}
.share-popup,
.uni-popup__wrapper-box {
	.share-title {
		line-height: 60rpx;
		font-size: $font-size-toolbar;
		padding: 15rpx 0;
		text-align: center;
	}

	.share-content {
		display: flex;
		display: -webkit-flex;
		-webkit-flex-wrap: wrap;
		-moz-flex-wrap: wrap;
		-ms-flex-wrap: wrap;
		-o-flex-wrap: wrap;
		flex-wrap: wrap;
		padding: 15rpx;

		.share-box {
			flex: 1;
			text-align: center;

			.share-btn {
				margin: 0;
				padding: 0;
				border: none;
				line-height: 1;
				height: auto;
				text {
					margin-top: 20rpx;
					font-size: $font-size-tag;
					display: block;
					color: $color-title;
				}
			}

			.iconfont {
				font-size: 80rpx;
				line-height: initial;
			}
			.iconfuzhilianjie {
				color: #07c160;
			}
		}
	}

	.share-footer {
		height: 90rpx;
		line-height: 90rpx;
		border-top: 2rpx #f5f5f5 solid;
		text-align: center;
		color: #666;
	}
}
/* 说明弹框 */
.tips-layer {
	background: #fff;
	z-index: 999;
	height: 40%;
	width: 100%;

	.head {
		position: relative;
	}

	.title {
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: $font-size-toolbar;
		font-weight: 700;
	}

	text {
		position: absolute;
		top: 8rpx;
		right: 22px;
		font-size: $font-size-toolbar;
		font-weight: 500;
	}

	.body {
		width: 100%;
		height: calc(100% - 80rpx);
		overflow-y: scroll;

		.detail {
			padding: 20rpx 30rpx;

			.font-size-base {
				margin-bottom: 10rpx;
			}
		}
	}
}
</style>
<style scoped>
/deep/ .reward-popup .uni-popup__wrapper-box {
	background: none !important;
	max-width: unset !important;
	max-height: unset !important;
}
</style>